package chapter30;

import java.util.ArrayList;

public class Cxy_test {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<String> arrays = new ArrayList<String>();
        arrays.add("黄俊翔");
        arrays.add("阿翔");
        arrays.add("小翔");
        arrays.add("大翔");
        arrays.add("黄阿玛");
        arrays.add("黄sir");

        // Create tasks
        Runnable printA = new PrintString("hello", 50);
        Runnable printB = new PrintString("goodbye", 50);
        Runnable printlist = new Printlist(arrays);

        // Create threads
        Thread thread1 = new Thread(printA);
        Thread thread2 = new Thread(printB);
        Thread thread3 = new Thread(printlist);

        // Start threads
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class PrintString implements Runnable{
    private String strToPrint;
    private int times;
    public PrintString(String str,int t){
        strToPrint = str;
        times = t;
    }
    public void run(){
        for (int i =0;i<times;i++){
            System.out.print(" "+strToPrint);
        }
    }
}
class Printlist implements Runnable{
    private ArrayList list;
    public Printlist(ArrayList list1){
        list = list1;
    }
    public void run(){
        for (int i = 0;i<list.size();i++){
            System.out.print(" "+list.get(i));
        }
    }
}